package com.swagger.doc.swaggertodoc.controller;

import com.swagger.doc.swaggertodoc.req.Person;
import com.swagger.doc.swaggertodoc.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @author yanghui
 * @version 1.0.0
 * @ClassName EsController.java
 * @Description TODO
 * @Param
 * @createTime 2020年08月29日 15:24:00
 */
@RestController
@RequestMapping("/es")
public class EsController {
    @Autowired
    private PersonService personService;

    @RequestMapping("/book/{id}")
    @ResponseBody
    public Person getBookById(@PathVariable String id) {
        Optional<Person> opt = personService.findById(id);
        Person book = opt.get();
        System.out.println(book);
        return book;
    }

    @RequestMapping("/save")
    @ResponseBody
    public void Save() {
        Person book = new Person("1", "ES入门教程", "ddf", "2021-10-01");
        System.out.println(book);
        personService.save(book);
    }

}
